Xbasic .aex files

Description

Specify a comma delimited list of .aex files. These files contain compiled Xbasic functions that can be used in any of the server-side event handlers.

You do not have to list .aex files here if you have specified the .aex files in the Project Properties dialog. Concerning the 'Aex files property', if you specify .aex files here they will be automatically added to the 'Aex files' property in the Project Properties. The Project Properties dialog is opened from the toolbar of the Web Projects Control Panel.

An .aex file is a library of functions. It lets you take all of the global functions that you have defined in a project and put them into a single file, with the file extension .aex. This enables you to use these functions in the Xbasic handlers of your components. These files are useful if you have code that exists outside of a component that you want to include with that component when the component is published. Otherwise, if you publish a component that requires certain function definitions that are not defined inside the scope of that component, then the published application will not know where to find these functions and that part of the component might fail.

Before 'projects' or the 'Web Project Control Panel' existed in Alpha Anywhere, aex libraries were usually loaded by hand, by using a load function. This approach presented some problems, though, particularly with caching issues that happened during publishing. When an aex file was published with a component the functions in the aex file were cached. This cached data would then override any new function definitions that were added to the aex file in subsequent publishing attempts, thus making it difficult to publish updates to a component. This problem was eventually dealt with when creating a connection to aex files became something that was done using a property setting, like the 'Xbasic aex files' property shown here; rather than by typing in some lines of code. Internally, Alpha Anywhere makes use of a temporary folder and a fair amount of coding in order to get around the caching issues. Using the property settings to add aex files is highly recommended.

The ability to automatically to include aex libraries using a property setting was added to Alpha Anywhere after the idea of 'projects' and the 'Web Project Control Panel' were fully implemented. You can add aex files at either the component or project level. To add aex files to a UX component you fill out the name of the aex file that you wish to include using this, the 'Xbasic aex files', property. If you want to use an aex library with multiple components you can define the aex file(s) you wish to connect to in the 'Aex files' section of the 'Web Project Properties'. Both of these methods are described below. If you define a connection to an aex file at the project level, there is no need to define it at the component level as well; as the aex file information in the project properties section will be published with the component.

For a video explanation of .aex files see the guide below or watch these videos of 'Using AEX Files to Reference Global Functions': Part 1 and Part 2.

Define a Function to Add to an .aex File

  1. From the Web Project Control Panel click the 'Interactive Window' button.

    images/xaf.png
  2. Click the 'New Function' button, the 'f()' icon in the Code Editor toolbar.

    images/xaf2.png
  3. Name the new function 'showDateTime' and click OK.

    images/xaf3.png
  4. Back in the Code Editor, define the new function as follows:

    function showDateTime as c ()
    showDateTime = "<b>Current</b> date and time is: " + now()
    end function
    images/xaf4.png
  5. Click 'Save'

    images/xaf5.png
  6. To make sure the function works open the 'Interactive' pane a type '?showDateTime()', then hit the Enter key. The date and time should be displayed

    ?showDateTime()
    images/xaf6.png

Creating the .AEX File

Once a function has been created there are two ways that you can add it to an aex file. The standard way in which an .AEX file is created is by right clicking on white-space in the Code tab on the Control Panel and then selecting the 'Compile scripts and functions into an .aex file' from the menu. After you have created the .AEX file, you need to copy the .AEX file into your Web Project folder so that it can be published when you publish your project files.

images/xaf29.png
'Compile scripts and functions into an .aex file'

The second, and easier, approach to creating aex files is to check the 'Compile Functions into an .AEX File checkbox when you publish your files.

Use the Function in a UX Component

  1. In the UX Builder on the UX controls page open the 'Data Controls' menu. Click on the [List] option to add a list control to the component.

    images/xaf9.png
  2. Highlight the list control in the properties list on the right click on the [...] button next to the 'List properties' property in the List Properties section. The List Builder will open.

    images/xaf10.png
  3. On the List Builder's Data Source pane select 'Static' for the 'Data Source Type'.

    images/xaf11.png
  4. Click the [...] button next to the 'Static data' property.

    images/xaf12.png
  5. In the 'Static Choices' dialog click the 'Sample data' hyperlink in the lower left-hand corner.

    images/xaf13.png
  6. Select the 'Name and addresses' sample in the Sample Data dialog and click OK to add it to the Static Choices dialog. Click OK to close the Static Choices dialog.

    images/xaf14.png
  7. Open the 'Fields' pane. Click the 'Add Item' button in the lower right. Select the 'Custom Control' option.

    images/xaf15.png
  8. Give the field the name 'Time'

    images/xaf16.png
  9. Highlight the custom control field. In the properties list on the Fields pane click the [...] button next to the 'Definition' property under the 'Custom Control Properties' section.

    images/xaf17.png
  10. In the definition find the three lines of code that looks like this:

    Time_render = <<%html%
    Specify the HTML to be returned.
    %html%
    images/xaf18.png
  11. Replace the html value with the showDateTime() function you defined in the first section of this guide. The function should appear in the autofill. Click OK.

    Time_render = showDateTime()
    images/xaf19.png
  12. Open the 'List Layout Pane' Use the blue > arrow to move the 'Time' field from the 'Available Fields' list to the 'Columns in List' section. Click OK to close the list builder.

    images/xaf20.png
  13. If you try to run the component in Live Preview you should receive an error message, due to the fact that the component is not yet tied to the project's aex file. The next section covers how to do this.

Adding the aex File to a UX Component

  1. Open the Web Projects Control Panel. At the very top of the screen note the name of your project's main .adb file, right next to the Alpha Anywhere logo. In this case 'HelloAlpha'

    images/xaf21.png
  2. Go back to the UX control with the custom component. Open the 'UX Properties' page and scroll down to the 'Other' properties section. Click the [...] button next to the 'Xbasic .aex files' property.

    images/xaf7.png
  3. In the 'AEX Files' dialog type the name of your project, adding an .aex extension to it.

    images/xaf8.png
  4. If you have not added this file to your project properties already you should receive this notice that Alpha Anywhere will do it automatically for you, click 'Yes'.

    images/notice.png
  5. The defined .aex file. You can add additional .aex files as needed, provided they are delimited by a comma.

    images/xaf22.png
  6. Run the component in Live Preview. The list control should now work.

    images/xaf23.png

Adding an aex File to a Project

  1. From the Web Projects Control Panel click on the 'Project Properties' button.

    images/xaf24.png
  2. Click the [...] button next to the 'File list' property in the 'Aex files' section.

    images/xaf25.png
  3. Add the name of the .aex file that you want to connect to and click OK.

    images/xaf26.png

Including .aex Files when Publishing

This is the second approach to creating .aex files. By checking the 'Compile Functions into .AEX File' checkbox, you can automatically compile the functions into an .AEX file every time you publish your files. This option is generally preferred as it automatically copies the AEX file into your Web Project folder. As described earlier in this guide, the other approach is to right click on the white space in the Code tab of the Control Panel and select the 'Compile scripts and functions into .aex file' from the menu.

  1. On the Web Projects Control Panel highlight the file you wish to publish and click 'Publish' in the toolbar.

    images/xaf27.png
  2. Make sure to check the 'Compile functions into an .AEX file?' checkbox.

    images/xaf28.png

When you choose the second option (by checking the Compile Functions into .AEX File checkbox), the name of the .AEX file that is created is set to the same name as the current Workspace (i.e. the .abd file that you have open). For example, if the .adb file that you have open is called MyWebProjects.adb, the .AEX file that is created is called 'MyWebProjects.aex'. Also, the Aex files property in the Project Properties dialog is automatically set, saving you from having to manually set this property.

Use of Xbasic Function Libraries

You might want to consider using Xbasic Function Libraries for shared Xbasic functions rather than using .AEX files. Xbasic Function Libraries are easy to work with, they can also be defined in the Web Project Control Panel, and they automatically get published when you publish your application. Inside each component that must reference a function defined in an Xbasic Function Library there is a property where you can explicitly link the Xbasic Function Libraries that your component references.